﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Reflection;
using Ppt = Microsoft.Office.Interop.PowerPoint;
using MVVM.Core;

namespace ObjectModel.PowerPoint.RulesModel.Old
{
    /// <summary>
    /// Provides a base class for a set of serializable instructions for performing
    /// some action on a PowerPoint shape object.
    /// </summary>
    public abstract class Action : NotificationBase
    {
        [XmlIgnore]
        public Ppt.Shape TargetShape { get; set; } // Need to set this after deserialization
        
        public List<string> TargetProperties { get; set; }

        [XmlIgnore]
        public dynamic TargetObject
        {
            get
            {
                object o = TargetShape;
                foreach (string propName in TargetProperties)
                    o = o.GetType().GetProperty(propName).GetValue(TargetShape, null);

                return o;
            }

            set
            {
                dynamic child = value;
                object parent = child.Parent;
                PropertyInfo[] props = parent.GetType().GetProperties();
                var prop = props.Where(p => p.Name == child.GetType().Name);
            }
        }

        public abstract void Perform();
    }
}
